﻿using System;
using System.Data;

namespace Common
{
    [Serializable]
    public class unit_infoData
    {

        public const string UNIT_NUMBERField = "@unit_number";

        public const string PRIMARYKEY_Field = @"unit_number";

        public const string UNIT_SHELF_NUMBERField = "@unit_shelf_number";

        public const string PHONE1Field = "@phone1";

        public const string PHONE2Field = "@phone2";

        public const string PHONE3Field = "@phone3";

        public const string CREATE_USER_IDField = "@create_user_id";

        public const string CREATE_TIMESTAMPField = "@create_timestamp";

        public const string UPDATE_USER_IDField = "@update_user_id";

        public const string UPDATE_TIMESTAMPField = "@update_timestamp";

        private String _unit_number;

        private String _unit_shelf_number;

        private String _phone1;

        private String _phone2;

        private String _phone3;

        private Int32 _create_user_id;

        private DateTime _create_timestamp;

        private Int32 _update_user_id;

        private DateTime _update_timestamp;

        public String unit_number
        {
            get { return _unit_number; }
            set { _unit_number = value; }
        }
        public String unit_shelf_number
        {
            get { return _unit_shelf_number; }
            set { _unit_shelf_number = value; }
        }
        public String phone1
        {
            get { return _phone1; }
            set { _phone1 = value; }
        }
        public String phone2
        {
            get { return _phone2; }
            set { _phone2 = value; }
        }
        public String phone3
        {
            get { return _phone3; }
            set { _phone3 = value; }
        }
        public Int32 create_user_id
        {
            get { return _create_user_id; }
            set { _create_user_id = value; }
        }
        public DateTime create_timestamp
        {
            get { return _create_timestamp; }
            set { _create_timestamp = value; }
        }
        public Int32 update_user_id
        {
            get { return _update_user_id; }
            set { _update_user_id = value; }
        }
        public DateTime update_timestamp
        {
            get { return _update_timestamp; }
            set { _update_timestamp = value; }
        }
        public unit_infoData()
        {
            _unit_number = "";
            _unit_shelf_number = "";
            _phone1 = "";
            _phone2 = "";
            _phone3 = "";
            _create_user_id = 0;
            _create_timestamp = DateTime.Now;
            _update_user_id = 0;
            _update_timestamp = DateTime.Now;
        }
    }

    public class unit_infoDataFactory
    {
        public static unit_infoData Construct(IDataReader reader)
        {
            unit_infoData data = new unit_infoData();

            try { data.unit_number = Convert.ToString(reader["unit_number"]); }
            catch { }

            try { data.unit_shelf_number = Convert.ToString(reader["unit_shelf_number"]); }
            catch { }

            try { data.phone1 = Convert.ToString(reader["phone1"]); }
            catch { }

            try { data.phone2 = Convert.ToString(reader["phone2"]); }
            catch { }

            try { data.phone3 = Convert.ToString(reader["phone3"]); }
            catch { }

            try { data.create_user_id = Convert.ToInt32(reader["create_user_id"]); }
            catch { }

            try { data.create_timestamp = Convert.ToDateTime(reader["create_timestamp"]); }
            catch { }

            try { data.update_user_id = Convert.ToInt32(reader["update_user_id"]); }
            catch { }

            try { data.update_timestamp = Convert.ToDateTime(reader["update_timestamp"]); }
            catch { }

            return data;
        }
        public static String GetPrimaryKey(DataTable dt)
        {
            return GetPrimaryKey(dt, 0);
        }
        public static String GetPrimaryKey(DataTable dt, int rowIndex)
        {
            String PrimaryKey = "";

            if (dt.Rows.Count < rowIndex + 1)

                return "";

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return "";

            try { PrimaryKey = Convert.ToString(dr[unit_infoData.PRIMARYKEY_Field]); }
            catch { }

            return PrimaryKey;
        }
        public static unit_infoData Construct(DataTable dt)
        {
            return Construct(dt, 0);
        }
        public static unit_infoData Construct(DataTable dt, int rowIndex)
        {
            unit_infoData data = new unit_infoData();

            if (dt.Rows.Count < rowIndex + 1)

                return null;

            DataRow dr = dt.Rows[rowIndex];

            if (dr == null)

                return null;

            try { data.unit_number = Convert.ToString(dr["unit_number"]); }
            catch { }

            try { data.unit_shelf_number = Convert.ToString(dr["unit_shelf_number"]); }
            catch { }

            try { data.phone1 = Convert.ToString(dr["phone1"]); }
            catch { }

            try { data.phone2 = Convert.ToString(dr["phone2"]); }
            catch { }

            try { data.phone3 = Convert.ToString(dr["phone3"]); }
            catch { }

            try { data.create_user_id = Convert.ToInt32(dr["create_user_id"]); }
            catch { }

            try { data.create_timestamp = Convert.ToDateTime(dr["create_timestamp"]); }
            catch { }

            try { data.update_user_id = Convert.ToInt32(dr["update_user_id"]); }
            catch { }

            try { data.update_timestamp = Convert.ToDateTime(dr["update_timestamp"]); }
            catch { }

            return data;
        }
        public static unit_infoData Construct(DataRow dr)
        {
            unit_infoData data = new unit_infoData();

            try { data.unit_number = Convert.ToString(dr["unit_number"]); }
            catch { }

            try { data.unit_shelf_number = Convert.ToString(dr["unit_shelf_number"]); }
            catch { }

            try { data.phone1 = Convert.ToString(dr["phone1"]); }
            catch { }

            try { data.phone2 = Convert.ToString(dr["phone2"]); }
            catch { }

            try { data.phone3 = Convert.ToString(dr["phone3"]); }
            catch { }

            try { data.create_user_id = Convert.ToInt32(dr["create_user_id"]); }
            catch { }

            try { data.create_timestamp = Convert.ToDateTime(dr["create_timestamp"]); }
            catch { }

            try { data.update_user_id = Convert.ToInt32(dr["update_user_id"]); }
            catch { }

            try { data.update_timestamp = Convert.ToDateTime(dr["update_timestamp"]); }
            catch { }

            return data;
        }
        public static String GetPrimaryKey(DataRow dr)
        {
            String PrimaryKey = "";

            try { PrimaryKey = Convert.ToString(dr[unit_infoData.PRIMARYKEY_Field]); }
            catch { }
            return PrimaryKey;
        }

    }
}